<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib prefix="javatime" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<% String path = request.getContextPath();
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
%>
<!DOCTYPE html>
<html>
<head>
    <base href=<%=basePath%>
    <%@include file="../common_css.jsp"%>
    <style>
        .layui-upload-img{
            width: 92px;
            height: 92px;
            margin: 0 10px 10px 110px;
        }
    </style>
</head>
<body class="childrenBody">
<form class="layui-form" style="width:80%;">
    <input type="hidden" name="inputId" id="inputId" value="${cusDrive.id}">
    <input type="hidden" name="inputCusId" id="inputCusId" value="${cusDrive.cusId}">
    <input type="hidden" name="inputCarId" id="inputCarId" value="${cusDrive.carId}">
    <input type="hidden" name="inputDriveType" id="inputDriveType" value="${cusDrive.driveType}">
    <input type="hidden" name="inputUserId" id="inputUserId" value="${cusDrive.userId}">
    <div class="layui-form-item layui-row">
        <div class="layui-col-xs6">
            <label class="layui-form-label">客户姓名</label>
            <div class="layui-input-block">
                <select name="cusId"  id="cusId"
                        <c:if test="${cusDrive.cusId != null}">disabled</c:if>
                >
                    <option value="">请选择</option>
                </select>
            </div>
        </div>
        <div class="layui-col-xs6">
            <label class="layui-form-label">体验人姓名</label>
            <div class="layui-input-block">
                <input type="text" class="layui-input"
                       lay-verify="required" name="driveName" id="driveName"  value="${cusDrive.driveName}"
                       <c:if test="${cusDrive.cusId != null}">readonly</c:if>
                >
            </div>
        </div>
    </div>


    <div class="layui-form-item layui-row">
        <div class="layui-col-xs6">
            <label class="layui-form-label">手机号</label>
            <div class="layui-input-block">
                <input type="text" class="layui-input"
                       lay-verify="phone" name="phone" id="phone"  value="${cusDrive.phone}"
                       <c:if test="${cusDrive.cusId != null}">readonly</c:if>
                >
            </div>
        </div>
        <div class="layui-col-xs6">
            <label class="layui-form-label">试驾车辆</label>
            <div class="layui-input-block">
                <select name="carId"  id="carId"
                        <c:if test="${cusDrive.cusId != null}">disabled</c:if>
                >
                    <option value="" >请选择</option>
                </select>
            </div>
        </div>
    </div>
    <div class="layui-form-item layui-row">
        <div class="layui-col-xs6">
            <label class="layui-form-label">试驾类型</label>
            <div class="layui-input-block">
                <select name="driveType"  id="driveType"
                        <c:if test="${cusDrive.cusId != null}">disabled</c:if>
                >
                    <option value="" >请选择</option>
                </select>
            </div>
        </div>
        <div class="layui-col-xs6">
            <label class="layui-form-label">试驾时间</label>
            <div class="layui-input-block">
                <input type="text" class="layui-input" id="driveTime" name="driveTime"
                       value="${cusDrive.formattedDate}"
                       <c:if test="${cusDrive.cusId != null}">disabled</c:if>
                >
            </div>
        </div>
    </div>
    <div class="layui-form-item layui-row">
        <div class="layui-col-xs6">
            <label class="layui-form-label">主体验人</label>
            <input type="checkbox" name="primary" title="主" <c:if test="${cusDrive.primary==true}">checked</c:if>
                   <c:if test="${cusDrive.cusId != null}">disabled</c:if>
            >
        </div>
        <div class="layui-col-xs6">
            <label class="layui-form-label">分配员工</label>
            <div class="layui-input-block">
                <select name="userId"  id="userId"
                        <c:if test="${cusDrive.cusId != null}">disabled</c:if>
                >
                    <option value="" >请选择</option>
                </select>
            </div>
        </div>
    </div>
    <div class="layui-form-item layui-row">
        <label class="layui-form-label">服务处理</label>
        <div class="layui-input-block">
            <textarea  name="serverProce" id="serverProce" class="layui-textarea" lay-verify="required"></textarea>
        </div>
    </div>
    <div class="layui-form-item layui-row">
        <div class="layui-col-xs6">
            <label class="layui-form-label">身份证</label>
            <div class="layui-upload">
                <button type="button" class="layui-btn" id="test1">上传图片</button>
                <div class="layui-upload-list">
                    <img class="layui-upload-img" id="demo1">
                    <p id="demoText1"></p>
                </div>
            </div>
        </div>
        <div class="layui-col-xs6">
            <label class="layui-form-label">驾驶证</label>
            <div class="layui-upload">
                <button type="button" class="layui-btn" id="test2">上传图片</button>
                <div class="layui-upload-list">
                    <img class="layui-upload-img" id="demo2">
                    <p id="demoText2"></p>
                </div>
            </div>
        </div>
    </div>
    <br/>
    <div class="layui-form-item layui-row layui-col-xs12">
        <div class="layui-input-block">
            <button class="layui-btn layui-btn-lg" lay-submit=""
                    lay-filter="addOrUpdateCustomerServe">确认
            </button>
            <button class="layui-btn layui-btn-lg layui-btn-normal">取消</button>
        </div>
    </div>

</form>
<script type="text/javascript">
    layui.use(['form', 'layer','laydate','upload'], function () {
        var form = layui.form,
            layer = parent.layer === undefined ? layui.layer : top.layer,
            $ = layui.jquery
            ,upload = layui.upload;


        if($("input[name='inputUserId']").val()!=''){
            $.post("user/findUser",function (res) {
                for(var i=0;i<res.length;i++){
                    if($("input[name='inputUserId']").val() == res[i].id){
                        $("#userId").append("<option value=\""+res[i].id+"\" selected  >"+res[i].name+"</option>");
                    }else{
                        $("#userId").append("<option value=\""+res[i].id+"\"   >"+res[i].name+"</option>");
                    }
                }
                layui.form.render("select");
            });
        }
        $.post("customer/findCustomerById",{id:$("input[name='inputCusId']").val()},function (res) {
            for(var i=0;i<res.length;i++){
                if($("input[name='inputCusId']").val() == res[i].id){
                    $("#cusId").append("<option value=\""+res[i].id+"\"  selected >"+res[i].name+"</option>")
                }else{
                    $("#cusId").append("<option value=\""+res[i].id+"\"   >"+res[i].name+"</option>")
                }
            }
            layui.form.render("select");
        });
        $.post("car/findCarAll",function (res) {
            for(var i=0;i<res.length;i++){
                if($("input[name='inputCarId']").val() == res[i].id){
                    $("#carId").append("<option value=\""+res[i].id+"\" selected  >"+res[i].series+" "+res[i].model+"</option>");
                }else{
                    $("#carId").append("<option value=\""+res[i].id+"\"   >"+res[i].series+" "+res[i].model+"</option>");
                }
            }
            layui.form.render("select");
        });
        $.post("dictionaries/findDriveType",function (res) {
            for(var i=0;i<res.length;i++){
                if($("input[name='inputDriveType']").val() == res[i].valueId){
                    $("#driveType").append("<option value=\""+res[i].valueId+"\" selected  >"+res[i].valueName+"</option>");
                }else{
                    $("#driveType").append("<option value=\""+res[i].valueId+"\"   >"+res[i].valueName+"</option>");
                }

            }
            layui.form.render("select");
        });

        var uploadInst = upload.render({
            elem: '#test1'
            ,url: 'cusDrive/fileUpLoad' //改成您自己的上传接口
            ,before: function(obj){
                //预读本地文件示例，不支持ie8
                obj.preview(function(index, file, result){
                    $('#demo1').attr('src', result); //图片链接（base64）
                });
            }
            ,done: function(res){
                //如果上传失败
                if(res.code > 0){
                    return layer.msg('上传失败');
                }else {
                    return layer.msg('上传成功');

                }
            }
            ,data:{msg:"身份证",id : $("#inputId").val()}
        });

        var uploadInst = upload.render({
            elem: '#test2'
            ,url: 'cusDrive/fileUpLoad' //改成您自己的上传接口
            ,before: function(obj){
                //预读本地文件示例，不支持ie8
                obj.preview(function(index, file, result){
                    $('#demo2').attr('src', result); //图片链接（base64）
                });
            }
            ,done: function(res){
                //如果上传失败
                if(res.code > 0){
                    return layer.msg('上传失败');
                }else {
                    return layer.msg('上传成功');

                }
            }
            ,data:{msg:"驾驶证",id : $("#inputId").val()}
        });
        form.on('submit(addOrUpdateCustomerServe)',function (data) {
            var index= top.layer.msg("数据提交中,请稍后...",{icon:16,time:false,shade:0.8});
            var url = "cusDrive/updateNotes";
            $.post(url,{id:$("#inputId").val(),notes:$("#serverProce").val()},function (res) {
                if(res=='success'){
                    top.layer.msg("操作成功,请完善相关商机");
                    top.layer.close(index);
                    layer.closeAll("iframe");
                    // 刷新父页面
                    parent.location.reload();
                }
            });
            return false;
        });

    //     laydate.render({
    //         elem: '#driveTime',
    //         type: 'datetime',
    //         min:0,
    //         max:7,
    //         done: function(value, date, endDate){
    //             $.post("user/findUserByDriveTime",{date:value},function (res) {
    //                 $("#userId").children(":gt(0)").remove()
    //                 for(var i=0;i<res.length;i++){
    //                     $("#userId").append("<option value=\""+res[i].id+"\"   >"+res[i].name+"</option>");
    //                 }
    //                 // 重新渲染下拉框内容
    //                 layui.form.render("select");
    //             });
    //         }
    //     });
    //     if($("input[name='inputUserId']").val()!=''){
    //         $.post("user/findUser",function (res) {
    //             for(var i=0;i<res.length;i++){
    //                 if($("input[name='inputUserId']").val() == res[i].id){
    //                     $("#userId").append("<option value=\""+res[i].id+"\" selected  >"+res[i].name+"</option>");
    //                 }else{
    //                     $("#userId").append("<option value=\""+res[i].id+"\"   >"+res[i].name+"</option>");
    //                 }
    //             }
    //             layui.form.render("select");
    //         });
    //     }
    //     $.post("customer/findCustomerByState",function (res) {
    //         for(var i=0;i<res.length;i++){
    //             if($("input[name='inputCusId']").val() == res[i].id){
    //                 $("#cusId").append("<option value=\""+res[i].id+"\"  selected >"+res[i].name+"</option>")
    //             }else{
    //                 $("#cusId").append("<option value=\""+res[i].id+"\"   >"+res[i].name+"</option>")
    //             }
    //         }
    //         layui.form.render("select");
    //     });
    //     $.post("car/findCarAll",function (res) {
    //         for(var i=0;i<res.length;i++){
    //             if($("input[name='inputCarId']").val() == res[i].id){
    //                 $("#carId").append("<option value=\""+res[i].id+"\" selected  >"+res[i].series+" "+res[i].model+"</option>");
    //             }else{
    //                 $("#carId").append("<option value=\""+res[i].id+"\"   >"+res[i].series+" "+res[i].model+"</option>");
    //             }
    //         }
    //         layui.form.render("select");
    //     });
    //     $.post("dictionaries/findDriveType",function (res) {
    //         for(var i=0;i<res.length;i++){
    //             if($("input[name='inputDriveType']").val() == res[i].valueId){
    //                 $("#driveType").append("<option value=\""+res[i].valueId+"\" selected  >"+res[i].valueName+"</option>");
    //             }else{
    //                 $("#driveType").append("<option value=\""+res[i].valueId+"\"   >"+res[i].valueName+"</option>");
    //             }
    //
    //         }
    //         layui.form.render("select");
    //     });
    //

    });
</script>
</body>
</html>